import { Popconfirm, Space, TableColumnsType, Tag, Tooltip, Typography, Image, Badge } from 'antd'
import { NavigateFunction } from 'react-router-dom'
import { QualityOrderDetailVO, QualityOrderVO as ITableData } from './types'
import { BadgeColorMap, DIS_STATUSBANDBTNTEXT, STATUSBAND, USERTYPETEXT } from '@/constant'
import { getImageByUrl } from '@/utils/getImageByUrl'
import { CONTRACT_STATUS_TEXT, QC_STATGE_TEXT, QC_STATUS_TEXT } from '@/constant/purchase'
import PermissionLink from '@/components/PermissionLink'
export const useIndexColumns = ({
  navigate,
  onReply,
  onRun,
  onViewLogs,
  onViewCon,
  isRoot,
}: {
  navigate: NavigateFunction
  onReply: (info: ITableData) => void
  onRun: (info: ITableData) => void
  onViewLogs: (info: ITableData) => void
  onViewCon: (info: ITableData) => void
  isRoot: boolean
}): TableColumnsType<ITableData> => [
  {
    title: 'QC单号',
    dataIndex: 'qualityOrderCode',
    key: 'qualityOrderCode',
    align: 'center',
    width: 150,
    fixed: 'left',
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    key: 'createTime',
    align: 'center',
    width: 200,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '供应商',
    dataIndex: 'supplierName',
    key: 'supplierName',
    align: 'center',
    width: 180,
    ellipsis: {
      showTitle: false,
    },
    render: (info) => {
      return info ? (
        <Tooltip placement="top" title={info}>
          {info}
        </Tooltip>
      ) : (
        '-'
      )
    },
  },
  {
    title: 'QC阶段',
    dataIndex: 'qualityPhase',
    key: 'qualityPhase',
    align: 'center',
    width: 150,
    render: (info) => {
      return <Badge color={BadgeColorMap[info]} text={QC_STATGE_TEXT[info] || '-'} />
    },
  },
  {
    title: 'QC状态',
    dataIndex: 'qualityStatus',
    key: 'qualityStatus',
    align: 'center',
    width: 150,
    render: (info) => {
      return <Badge color={BadgeColorMap[info]} text={QC_STATUS_TEXT[info] || '-'} />
    },
  },
  {
    title: '预约QC时间',
    dataIndex: 'scheduleQualityTime',
    key: 'scheduleQualityTime',
    align: 'center',
    width: 150,
    render: (info, rows) => {
      return rows?.finalInspectionTimeTooEarly == 1 ? (
        <Tooltip placement="top" title={`距离合同交期还有${rows.dayNumToDeliveryTime}天，请注意尾查时间`}>
          <span style={{ color: 'red', cursor: 'pointer' }}>{info || '-'}</span>
        </Tooltip>
      ) : (
        info || '-'
      )
    },
  },
  {
    title: 'QC人员',
    dataIndex: 'qualityInspector',
    key: 'qualityInspector',
    align: 'center',
    width: 120,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '回复QC时间',
    dataIndex: 'replyQualityTime',
    key: 'replyQualityTime',
    align: 'center',
    width: 150,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: 'QC结论',
    dataIndex: 'remark',
    key: 'remark',
    align: 'center',
    fixed: 'right',
    width: 100,
    render: (_, rows) => {
      return (
        <Space size={'large'}>
          <Typography.Link onClick={() => onViewCon(rows)}>查看</Typography.Link>
        </Space>
      )
    },
  },
  {
    title: '操作',
    fixed: 'right',
    align: 'center',
    width: 250,
    render: (_, rows) => {
      return (
        <Space size={'large'}>
          {rows.qualityStatus == 1 ? (
            <PermissionLink permission="replyQc" onClick={() => onReply(rows)}>
              回复QC
            </PermissionLink>
          ) : null}
          {isRoot && (rows.qualityStatus == 1 || rows.qualityStatus == 5) ? (
            <PermissionLink permission="checkQc" onClick={() => onRun(rows)}>
              执行QC
            </PermissionLink>
          ) : null}
          {isRoot ? <Typography.Link onClick={() => onViewLogs(rows)}>查看日志</Typography.Link> : null}
        </Space>
      )
    },
  },
]

export const useInnerColumns = (): TableColumnsType<QualityOrderDetailVO> => [
  {
    title: '采购订单号',
    dataIndex: 'purchaseOrderCode',
    key: 'purchaseOrderCode',
    align: 'center',
    fixed: 'left',
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '款式编码',
    dataIndex: 'productSimpleVO',
    key: 'spuCode',
    align: 'center',
    render: (info) => {
      return info ? info?.spuCode : '-'
    },
  },
  {
    title: '助记码',
    dataIndex: 'productSimpleVO',
    key: 'designCode',
    align: 'center',
    render: (info) => {
      return info ? info?.designCode : '-'
    },
  },
  {
    title: '款式名称',
    dataIndex: 'productSimpleVO',
    key: 'spuName',
    align: 'center',
    render: (info) => {
      return info ? info?.spuName : '-'
    },
  },
  {
    title: '商品分类',
    dataIndex: 'productSimpleVO',
    key: 'className',
    align: 'center',
    render: (info) => {
      return info ? info?.className : '-'
    },
  },
  {
    title: '商品条码',
    dataIndex: 'productSimpleVO',
    key: 'skuCode',
    align: 'center',
    render: (info) => {
      return info?.skuCode || '-'
    },
  },
  {
    title: '尺码',
    dataIndex: 'productSimpleVO',
    key: 'size',
    align: 'center',
    render: (info) => {
      return info?.size || '-'
    },
  },
  {
    title: '颜色',
    dataIndex: 'productSimpleVO',
    key: 'colorDetailName',
    align: 'center',
    render: (info) => {
      return info?.colorDetailName || '-'
    },
  },
  {
    title: '下单数量',
    dataIndex: 'orderQty',
    key: 'orderQty',
    align: 'center',
    render: (info) => {
      return info || '-'
    },
  },
  // {
  //   title: '采购价',
  //   dataIndex: 'purchasePrice',
  //   key: 'purchasePrice',
  //   align: 'center',
  //   render: (info) => {
  //     return info || '-'
  //   },
  // },
  // {
  //   title: '采购金额',
  //   dataIndex: 'purchaseMoney',
  //   key: 'purchaseMoney',
  //   align: 'center',
  //   render: (info) => {
  //     return info || '-'
  //   },
  // },
]
